<template>
    <div class="operation-but-group">
      <el-button size="small" @click="handleDelete">
          删除
        </el-button>
        <el-button size="small" @click="getFresh">
          刷新
        </el-button>
      </div>
  </template>
  <script>
  import { mapGetters, mapState } from "vuex"
    export default{
      name: 'TaskButtonGroup',
      computed:{
        ...mapGetters(['selectedIds']),
        ...mapState({
          selectedTaskArr: state => state.taskDetail.selectedTaskArr,
        })
      },
      props: {
        fromPage: {
          type: String,
          default: ''
        }
      },
      methods:{
        // 刷新
        getFresh(){
          if(this.fromPage === 'taskRun'){
            this.$store.dispatch('task/setTaskRunFresh', true)
          }else if(this.fromPage === 'taskDetail'){
            this.$store.dispatch('taskDetail/setTaskDetailFresh', true)
          }
        },
        //删除
        handleDelete: function() {
          if(this.fromPage === 'taskRun' && this.selectedIds.length == 0) {
            this.$message({
              message: '请选中需要删除的任务',
              type: 'warning'
            })
            return
          } 
          if(this.fromPage === 'taskDetail' && this.selectedTaskArr.length == 0) {
            this.$message({
              message: '请选中需要删除的任务',
              type: 'warning'
            })
            return
          } 
          this.$emit('openDeleteDialog')
        },
      }
    }
  </script>
  <style lang="scss" scoped>
    @import '@/styles/mixin.scss';//引用此混合样式
    .operation-but-group{
      @include operation-button-group 
    }
  </style>
  